<!DOCTYPE HTML>
<html>

<head>
	<meta charset="utf-8">
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
	<meta http-equiv="Cache-Control" content="no-siteapp" />
	<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5shiv.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/h-ui/css/H-ui.min.css" />
	<link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/H-ui.admin.css" />
	<link rel="stylesheet" type="text/css" href="../lib/Hui-iconfont/1.0.8/iconfont.css" />
	<link rel="stylesheet" type="text/css" href="../static/h-ui.admin/skin/default/skin.css" id="skin" />
	<link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/style.css" />
	<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
	<title>添加商户</title>
	<script type="text/javascript" src="../lib/jquery/1.9.1/jquery.min.js"></script>
	<script type="text/javascript" src="../lib/layer/2.4/layer.js"></script>
	<script type="text/javascript" src="../static/h-ui/js/H-ui.min.js"></script>
	<script type="text/javascript" src="../static/h-ui.admin/js/H-ui.admin.js"></script>
	<!--/_footer 作为公共模版分离出去-->

	<!--请在下方写此页面业务相关的脚本-->
	<script type="text/javascript" src="../lib/My97DatePicker/4.8/WdatePicker.js"></script>
	<script type="text/javascript" src="../lib/jqueryPage/paging.min.js"></script>
	<script type="text/javascript" src="../lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
	<script type="text/javascript" src="../lib/laypage/1.2/laypage.js"></script>
	<script src="../lib/jrender.min.js" type="text/javascript"></script>
	<script src="../js/config.js"></script>
	<script>
		$(function () {
			$(".inputDisabled").attr("disabled", "disabled");
			var account = $.cookie('user__userName');
			var md5 = $.cookie('user__code');
			$.ajax({
				type: 'POST',
				url: $.webConfig.basicUrl + '/chuyangPay/user/getUserDBConfig',
				data: {
					account: account,
					md5: md5,
				},
				dataType: "json",
				success: function (data) {
					if (data['code'] == 200) {

						// $('#tianXiaMchId').val(data['data']['tianXiaMchId']);
						// $('#tianXiaSignKey').val(data['data']['tianXiaSignKey']);	

						$('#saoBeiMerchant_no').val(data['data']['saoBeiMerchant_no']);
						$('#saoBeiTermianl_id').val(data['data']['saoBeiTermianl_id']);
						// $('#lingmerchant').val(data['data']['ldmerNo']);
						// $('#lingKey').val(data['data']['ldkey']);
						// $('#lingaddress').val(data['data']['ldUrl']);
					} else {
						layer.alert(data['msc']);
					}
				},
				error: function (err) {
					console.log(err);
				}
			})
		})
		//	function checkval(){
		//		var wxAppId=$('#wxAppId').val();
		//		var wxKey=$('#wxKey').val();
		//		var wxMchId=$('#wxMchId').val();
		//		var zfbAppid=$('#zfbAppid').val();
		//		var zfbPid=$('#zfbPid').val();
		//		var zfbPublicKey=$('#zfbPublicKey').val();
		//		var zfbPirvateKey=$('#zfbPirvateKey').val();
		//		if (wxAppId==null||wxAppId=="") {
		//			$(".inputDisabled").attr("disabled","disabled");
		//		}
		//	}
	</script>
</head>

<body>

	<article class="page-container">
		<h3>天下支付</h3>
		<table class="table table-border table-bordered table-bg">
			<thead>
				<tr>
					<th scope="col" colspan="9">天下支付配置列表</th>
				</tr>
				<tr class="text-c">
					<th width="40">ID</th>
					<th width="150">天下支付商户号</th>
					<th width="150">天下支付秘钥</th>
					<th width="130">加入时间</th>
					<th width="90">备注</th>
					<th width="100">是否已启用</th>
					<th width="100">操作</th>
				</tr>
			</thead>
			<tbody class="j-specCard-box"></tbody>
			<!-- <td class="td-status"><span class="label radius">使用中</span></td> -->

			<script type="text/x-jsrender" id="j-specCard">
				{{for data}}
				<tr class="text-c" config-id="{{:config_Id}}">
					<td>{{:#index + 1}}</td>
					<td>{{:tianXiaMchId}}</td>
					<td>{{:tianXiaSignKey}}</td>

					<td>{{timeFilter:time}}</td>

					<td>{{:beizhu}}</td>

					<td class="td-status">
						<span class="label radius">未启用</span>
					</td>

					<td class="td-manage">
						<a style="text-decoration:none" href="javascript:;" class="edit-tianxia btn" title="启用" config-id="{{:config_Id}}">
							<i class="Hui-iconfont">&#xe6df;</i>
						</a>
						<a title="删除" href="javascript:;" class="ml-5 dle-tianxia btn" style="text-decoration:none" config-id="{{:config_Id}}">
							<i class="Hui-iconfont"></i>
						</a>
					</td>
				</tr>
				{{/for}}
			</script>

		</table>

		<form class="form form-horizontal mt-20">
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">
					<span class="c-red">*</span>天下支付商户号：</label>
				<div class="formControls col-xs-4 col-sm-5">
					<input type="text" class="input-text" placeholder="天下支付商户号" id="tianXiaMchId" name="tianXiaMchId">
				</div>
			</div>

			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">
					<span class="c-red">*</span>天下支付秘钥：</label>
				<div class="formControls col-xs-4 col-sm-5">
					<input type="text" class="input-text" placeholder="天下支付秘钥" id="tianXiaSignKey" name="tianXiaSignKey">
				</div>
			</div>

			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">
					<span class="c-red">*</span>备注：</label>
				<div class="formControls col-xs-4 col-sm-5">
					<input type="text" class="input-text" placeholder="天下支付秘钥" id="tianXiaBeiZhu">
				</div>
			</div>

			<div class="row cl">
				<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
					<input id="add_tianxia" class="btn btn-primary radius" type="button" value="&nbsp;&nbsp;添加天下支付配置&nbsp;&nbsp;">
				</div>
			</div>
		</form>



		<form class="form form-horizontal mt-20" id="form-admin-add">
			<hr class="mt-20" />

			<h3>扫呗</h3>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">
					<span class="c-red">*</span>扫呗支付商户号：</label>
				<div class="formControls col-xs-4 col-sm-5">
					<input type="text" class="input-text inputDisabled" placeholder="扫呗支付商户号" id="saoBeiMerchant_no" name="saoBeiMerchant_no">
				</div>
			</div>

			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">
					<span class="c-red">*</span>扫呗支付终端号：</label>
				<div class="formControls col-xs-4 col-sm-5">
					<input type="text" class="input-text inputDisabled" placeholder="扫呗支付终端号" id="saoBeiTermianl_id" name="saoBeiTermianl_id">
				</div>
			</div>

			<div style="display: none;outline: none;padding: 0 15px;" id="contentdiv">
				<div class="row cl">
					<label class="form-label col-xs-5 col-sm-4">
						<span class="c-red">*</span>用户名：</label>
					<div class="formControls col-xs-6 col-sm-7">
						<input type="text" class="input-text" id="username" name="" disabled="disabled">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-5 col-sm-4">
						<span class="c-red">*</span>密码：</label>
					<div class="formControls col-xs-6 col-sm-7">
						<input type="password" class="input-text" id="pwd" name="">
					</div>
				</div>
				<div class="row cl">
					<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
						<input id="submitcheck" class="btn btn-primary radius" type="button" value="&nbsp;&nbsp;确定&nbsp;&nbsp;">
					</div>
				</div>
				<script src="js/cookie.js" type="text/javascript" charset="utf-8"></script>
				<script>
					var account = $.cookie('user__userName');

					$("#username").val(account);
					$("#submitcheck").click(function () {
						var pwd = $('#pwd').val();
						if (account && pwd) {
							$.ajax({
								type: 'POST',
								url: $.webConfig.basicUrl + '/chuyangPay/user/userLogin',
								data: {
									account: account,
									pwd: pwd
								},
								dataType: "json",
								success: function (data) {
									if (data['code'] == 200) {
										layer.close(layer.index);
										$(".inputDisabled").removeAttr("disabled", "disabled");
										successnum++;
										$.cookie('successnum', successnum, {
											expires: 7,
											path: '/'
										})
									} else {
										layer.alert(data['msc']);
									}
								},
								error: function (err) {
									layer.alert('不好意思，我们的服务器在开小差');
								}
							})

						}
					})
				</script>
			</div>
			<div class="row cl">
				<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
					<input id="changemes" class="btn btn-primary radius" type="button" value="&nbsp;&nbsp;修改&nbsp;&nbsp;">
					<input id="updata" class="btn btn-primary radius" type="button" value="&nbsp;&nbsp;保存&nbsp;&nbsp;">
				</div>
			</div>
		</form>
	</article>
	<script>
		// 天下商户配置
		// 获取已经配置的天下列表
		$(function () {
			$.ajax({
				type: 'post',
				url: $.webConfig.basicUrl + "/chuyangPay/user/getPayConfig",
				data: {
					account: $.cookie('user__userName'),
					md5: $.cookie('userall__code'),
					merchantNo: $.cookie('user_mcno')
				},
				dataType: "json",
				success: function (data) {
					console.log(data);
					jsRenderTpl = $.templates('#j-specCard');
					finalTpl = jsRenderTpl(data);
					$('.j-specCard-box').html(finalTpl);
					//获取用户信息
					$.ajax({
						type: 'POST',
						url: $.webConfig.basicUrl + '/chuyangPay/user/getUserDB',
						data: {
							account: $.cookie('user__userName'),
							md5: $.cookie('user__code')
						},
						dataType: "json",
						success: function (data) {
							if (data['code'] == 200) {
								$('.text-c[config-id="' + data['data']['payConfigId'] + '"]').css('background', '#f5fafe');
								$('.text-c[config-id="' + data['data']['payConfigId'] + '"]').find('.td-status span').text('已启用');
								$('.text-c[config-id="' + data['data']['payConfigId'] + '"]').find('.td-status span').addClass(
									'label-success');
								$('.text-c[config-id="' + data['data']['payConfigId'] + '"]').find('.edit-tianxia').hide();
								$('.text-c[config-id="' + data['data']['payConfigId'] + '"]').find('.dle-tianxia').hide();
							} else {
								layer.alert(data['msc']);
							}
						},
						error: function (err) {
							console.log(err);
						}
					});

				},
				error: function (XmlHttpRequest, textStatus, errorThrown) {

				}
			});

			// 启用天下支付
			$('body').on('click', '.edit-tianxia', function () {
				$('.edit-tianxia').attr('disabled', true);
				$.ajax({
					type: 'post',
					url: $.webConfig.basicUrl + "/chuyangPay/user/switchPayConfig",
					data: {
						account: $.cookie('user__userName'),
						md5: $.cookie('userall__code'),
						merchantNo: $.cookie('user_mcno'),
						id: $(this).attr('config-id')
					},
					dataType: "json",
					success: function (data) {
						console.log(data);
						$('.edit-tianxia').removeAttr('disabled');
						setTimeout(function () {
							window.location.replace(location.href);
						}, 600);
					},
					error: function (XmlHttpRequest, textStatus, errorThrown) {
						$('.edit-tianxia').removeAttr('disabled');
					}
				});
			});


			// 删除天下支付
			$('body').on('click', '.dle-tianxia', function () {
				$('.dle-tianxia').attr('disabled', true);
				$.ajax({
					type: 'post',
					url: $.webConfig.basicUrl + "/chuyangPay/user/delTianxiaPayConfig",
					data: {
						account: $.cookie('user__userName'),
						md5: $.cookie('userall__code'),
						merchantNo: $.cookie('user_mcno'),
						id: $(this).attr('config-id')
					},
					dataType: "json",
					success: function (data) {
						console.log(data);
						$('.dle-tianxia').removeAttr('disabled');
						setTimeout(function () {
							window.location.replace(location.href);
						}, 600);
					},
					error: function (XmlHttpRequest, textStatus, errorThrown) {
						$('.dle-tianxia').removeAttr('disabled');
					}
				});
			});


			// 添加天下支付
			$('#add_tianxia').on('click', function () {
				console.log(666)
				$('#add_tianxia').attr('disabled', 'true');
				var sub_obj = {
					tianxiaMerchantNo: {
						reg: 'required',
						val: $('#tianXiaMchId').val(),
						msg: '商户号不能为空!'
					},
					tianxiaMerchantKisg: {
						reg: 'required',
						val: $('#tianXiaSignKey').val(),
						msg: '商户秘钥不能为空!'
					},
					beizhu: {
						reg: '',
						val: $('#tianXiaBeiZhu').val(),
						msg: '备注不能为空!'
					},
					merchantNo: {
						reg: 'required',
						val: $.cookie('user_mcno'),
						msg: '登录超时'
					},
					account: {
						reg: 'required',
						val: $.cookie('user__userName'),
						msg: '登录超时'
					},
					md5: {
						reg: 'required',
						val: $.cookie('userall__code'),
						msg: '登录超时'
					}
				}
				check(sub_obj, function (data) {
					$.ajax({
						type: 'post',
						url: $.webConfig.basicUrl + "/chuyangPay/user/addTianXiaPayConfig",
						data: data,
						dataType: "json",
						success: function (data) {
							if (data['code'] == 200) {
								layer.msg('添加成功!', {
									icon: 1,
									time: 1000
								});
								setTimeout(function () {
									window.location.replace(location.href);
								}, 600);
							}else{
								layer.alert(data['msc']);
							}
							$('#add_tianxia').removeAttr('disabled');
						},
						error: function (XmlHttpRequest, textStatus, errorThrown) {
							layer.msg('error!', {
								icon: 2,
								time: 1000
							});
							$('#add_tianxia').removeAttr('disabled');
						}
					});

				}, function (err) {
					layer.alert(err['msg']);
					$('#add_tianxia').removeAttr('disabled');
				});
			});

			// 检测变量输入是否正确
			function check(cheked_obj, success, error) {
				var con = 1;
				$.each(cheked_obj, function (key, val) {
					if (con == 1) {
						if (val['reg'] == 'required') {
							if (!val['val']) {
								error(val);
								con = 0;
							}
						}
					}
				});
				if (con == 1) {
					var data = {};
					$.each(cheked_obj, function (key, val) {
						data[key] = val['val'];
					});
					success(data);
				}
			}




			window.successnum = 0;
			$.cookie('successnum', successnum, {
				expires: 7,
				path: '/'
			})
			$("#changemes").click(function () {
				successnum = $.cookie('successnum');
				if (successnum == 0) {
					layer.open({
						type: 1,
						area: ['300px', '200px'],
						fix: false, //不固定
						maxmin: true,
						shade: 0.4,
						title: '身份验证',
						content: $('#contentdiv')
					});
				}
			});
			$("#updata").click(function () {
				layer.confirm('亲，确定不测试一下吗？', {
					btn: ['确定', '取消'] //按钮ldmerNo
				}, function () {
					account = $.cookie('user__userName');
					md5 = $.cookie('user__code');
					wxAppId = $('#wxAppId').val();
					wxKey = $('#wxKey').val();
					wxMchId = $('#wxMchId').val();
					zfbAppid = $('#zfbAppid').val();
					zfbPid = $('#zfbPid').val();
					zfbPublicKey = $('#zfbPublicKey').val();
					zfbPirvateKey = $('#zfbPirvateKey').val();

					tianXiaMchId = $('#tianXiaMchId').val();
					tianXiaSignKey = $('#tianXiaSignKey').val();

					saoBeiMerchant_no = $('#saoBeiMerchant_no').val();
					saoBeiTermianl_id = $('#saoBeiTermianl_id').val();


					ldmerNo = $('#lingmerchant').val();
					ldkey = $('#lingKey').val();
					ldUrl = $('#lingaddress').val();
					$.ajax({
						type: 'post',
						url: $.webConfig.basicUrl + "/chuyangPay/user/upUserDB",
						data: {
							account: account,
							md5: md5,
							wxAppId: wxAppId,
							wxKey: wxKey,
							wxMchId: wxMchId,
							zfbAppid: zfbAppid,
							zfbPid: zfbPid,
							zfbPublicKey: zfbPublicKey,
							zfbPirvateKey: zfbPirvateKey,
							tianXiaMchId: tianXiaMchId,
							tianXiaSignKey: tianXiaSignKey,
							saoBeiMerchant_no: saoBeiMerchant_no,
							saoBeiTermianl_id: saoBeiTermianl_id,
							ldmerNo: ldmerNo,
							ldkey: ldkey,
							ldUrl: ldUrl
						},
						dataType: "json",
						success: function (data) {
							if (data['code'] == 200) {
								layer.msg('成功!', {
									icon: 1,
									time: 1000
								});
							} else {
								layer.alert(data['msc']);
							}
						},
						error: function (XmlHttpRequest, textStatus, errorThrown) {
							layer.msg('error!', {
								icon: 2,
								time: 1000
							});
						}
					})


				}, function () {
					layer.msg('取消保存', {
						icon: 5
					});
				});

			});
		});

		$.views.converters("timeFilter", function (val) {
			var fmt = "yyyy-MM-dd hh:mm:ss";
			var data = new Date(val);
			var o = {
				"M+": data.getMonth() + 1, //月份 
				"d+": data.getDate(), //日 
				"h+": data.getHours(), //小时 
				"m+": data.getMinutes(), //分 
				"s+": data.getSeconds(), //秒 
				"q+": Math.floor((data.getMonth() + 3) / 3), //季度 
				"S": data.getMilliseconds() //毫秒 
			};

			if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (data.getFullYear() + "").substr(4 - RegExp.$1.length));
			for (var k in o)
				if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" +
					o[k]).substr(("" + o[k]).length)));
			return fmt;
		});
	</script>
</body>

</html>